package com.ktg.mes.chanjet.task;

import com.ktg.common.core.domain.Result;
import com.ktg.common.exception.BussinessException;
import com.ktg.common.utils.StringUtils;
import com.ktg.mes.chanjet.entity.TpItemType;
import com.ktg.mes.chanjet.response.InventoryClassResponse;
import com.ktg.mes.chanjet.service.TpItemTypeService;
import com.ktg.mes.chanjet.spi.ChanjetSpi;
import com.ktg.mes.md.domain.MdItem;
import com.ktg.mes.md.service.IMdItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.*;

/**
 * 存货MES分类同步
 */

@Slf4j
@Component("mesClassSyncDataTask")
public class MESClassSyncDataTask {

    @Autowired
    IMdItemService mdItemService;


    @Autowired
    ChanjetSpi chanjetSpi;


    public void execute(){
        try{
            List<MdItem> mdItems = mdItemService.selectMdItemAll();
            List<MdItem> mdBackUpItems = mdItemService.selectMdItemBackUpAll();
            if(mdItems.size() == 0 || mdBackUpItems.size() == 0) return;
            for (MdItem item :mdItems) {
                for(MdItem item2 :mdBackUpItems){
                    if(item.getItemCode().equals(item2.getItemCode())){
                        item.setProcessProductId(item2.getProcessProductId());
                        item.setProcessProductName(item2.getProcessProductName());
                    }
                }
            }
            mdItemService.saveOrUpdateBatch(mdItems);
        }catch (Exception ex){
            log.error("同步T+存货MES分类 信息出错",ex);
            throw new BussinessException("执行失败");
        }
    }

}
